import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

import component from './components'
Vue.use(component)// 在入口注册全局组件,然后其他组件可以直接使用

import * as filters from './filters'// 导入所有过滤器
import * as directives from '@/directives'
// 将所有导出对象合并到一个对象中
// console.log(Object.keys(directives)) // 将对象转换为数组形式['imgerror', 'aa', 'bb']
Object.keys(directives).forEach(item => {
  Vue.directive(item, directives[item]) // 全局注册全部自定义指令
  // console.log(directives[item])//导入的所有自定义指令对象(item是自定义指令名称)
})

Object.keys(filters).forEach(item => {
  Vue.filter(item, filters[item]) // 注册全局的过滤器
})
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

import Print from 'vue-print-nb' // 引入打印插件
Vue.use(Print) // 注册打印插件

import checkPermission from '@/MiXin/checkPermission'
Vue.mixin(checkPermission) // 意味着所有的组件都拥有 checkPermission的方法了

import i18n from '@/lang'// 导入多语言包

// 设置element为当前的语言
Vue.use(ElementUI, { i18n: (key, value) => i18n.t(key, value) })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n, // 在main.js中对挂载 i18n的插件
  render: h => h(App)
})
